package com.yenlien.traceyun.milk.controller;

import com.yenlien.traceyun.milk.entity.MilkDetection;
import com.yenlien.traceyun.milk.service.MilkDetectionService;
import com.yenlien.traceyun.webase.controller.BaseController;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.yenlien.traceyun.business.interceptor.UserAuthUtil.getLoginUser;

/**
 * @Date 2022/7/11
 * @Author jiaLong
 * @Descript
 */
@Api(tags = "检验检测")
@RestController
@RequestMapping("/milkDecetion")
public class DetectionController extends BaseController {

    @Autowired
    private MilkDetectionService detectionService;


    @PostMapping(value = "/save")
    public Object save(MilkDetection detection, HttpServletRequest request)  {
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        if(StringUtils.isEmpty(detection.getCompanyId())){
            detection.setCompanyId(getLoginUser().getCompanyId());
        }
        return success(detectionService.save(detection, files));
    }


    @PostMapping(value = "/findByList")
    public Object findByList(@RequestBody MilkDetection detection) {
        return success(detectionService.findByList(detection));
    }

    @PostMapping(value = "/findAll")
    public Object findAll() {
        return success(detectionService.findAll());
    }







}
